# 自媒体首页页面的对象库层
import allure
from selenium.webdriver.common.by import By

from Base.MediaBase.baseMedia import BasePage, BaseHandle


class HomePage(BasePage):
    def __init__(self):
        super().__init__()
        self.username = By.CSS_SELECTOR, "[class='user-name']"
        self.context_manage = By.XPATH, "//*[@class='el-submenu__title']/span[1]"
        self.publish_article = By.XPATH, "//ul[@role='menu'][1]/li[@role='menuitem'][1]"

    #      获取用户名信息元素
    def find_username(self):
        return self.get_element(self.username)

    #      找到内容管理
    def find_context_manage(self):
        return self.get_element(self.context_manage)

    #       找到发表文章
    def find_publish_article(self):
        return self.get_element(self.publish_article)


# 自媒体首页页面的操作层
class HomeHandel(BaseHandle):
    def __init__(self):
        self.home_page = HomePage()

    #       获取用户名元素文本
    @allure.step(title="获取用户名元素文本")
    def get_username(self):
        return self.home_page.find_username().text

    #       点击内容管理
    @allure.step(title="点击内容管理")
    def click_context_manage(self):
        self.home_page.find_context_manage().click()

    #       点击内容管理
    @allure.step(title="点击内容管理")
    def click_publish_article(self):
        self.home_page.find_publish_article().click()


# 自媒体首页页面的业务层
class HomeProxy:
    def __init__(self):
        self.home_handle = HomeHandel()

    # 定义获取用户名信息
    def get_username_msg(self):
        return self.home_handle.get_username()

    # 定义进入发表文章页面
    def go_publish_article(self):
        self.home_handle.click_context_manage()
        self.home_handle.click_publish_article()
